from pandas import DataFrame
import pandas as pd


def data_frame_merge():
  df1 = DataFrame(
      {'name': ['ZhangFei', 'GuanYu', 'a', 'b', 'c'], 'data1': range(5)})
  df2 = DataFrame(
      {'name': ['ZhangFei', 'GuanYu', 'A', 'B', 'C'], 'data2': range(5)})
  df3 = pd.merge(df1, df2, on='name')
  print("\ndf1:\n", df1)
  print("\ndf2:\n", df2)
  print("\ndf3:\n", df3)

def data_frame_inner():
  df1 = DataFrame(
      {'name': ['ZhangFei', 'GuanYu', 'a', 'b', 'c'], 'data1': range(5)})
  df2 = DataFrame(
      {'name': ['ZhangFei', 'GuanYu', 'A', 'B', 'C'], 'data2': range(5)})
  df3 = pd.merge(df1, df2, how="inner")
  print("\ndf3:\n", df3)


def data_frame_left():
  df1 = DataFrame(
      {'name': ['ZhangFei', 'GuanYu', 'a', 'b', 'c'], 'data1': range(5)})
  df2 = DataFrame(
      {'name': ['ZhangFei', 'GuanYu', 'A', 'B', 'C'], 'data2': range(5)})
  df3 = pd.merge(df1, df2, how="left")
  print("\ndf3:\n", df3)


def data_frame_right():
  df1 = DataFrame(
      {'name': ['ZhangFei', 'GuanYu', 'a', 'b', 'c'], 'data1': range(5)})
  df2 = DataFrame(
      {'name': ['ZhangFei', 'GuanYu', 'A', 'B', 'C'], 'data2': range(5)})
  df3 = pd.merge(df1, df2, how="right")
  print("\ndf3:\n", df3)

def data_frame_outer():
  df1 = DataFrame(
      {'name': ['ZhangFei', 'GuanYu', 'a', 'b', 'c'], 'data1': range(5)})
  df2 = DataFrame(
      {'name': ['ZhangFei', 'GuanYu', 'A', 'B', 'C'], 'data2': range(5)})
  df3 = pd.merge(df1, df2, how="outer")
  print("\ndf3:\n", df3)

if __name__ == '__main__':
  data_frame_outer()